package com.gaogzhen.designPattern.singleton;

public final class Singleton4 {
    // 问题1：解锁为什么加volatile
    private static volatile  Singleton4 instance = null;
    private Singleton4() {}
    // 问题2：对比实现3，说出这样做的意义
    public static  Singleton4 getInstance() {
        if(instance != null) {
            return instance;
        }
        synchronized(Singleton4.class) {
            // 问题3：为什么这里还要加空判断，之前不是判断过了吗？
            if(instance != null) {
                return instance;
            }
            instance = new Singleton4();
            return instance;
        }

    }
}
